
package com.panshi.controller;

import com.panshi.api.AnswerApi;
import com.panshi.po.Answer;
import com.panshi.po.AnswerAudit;
import com.panshi.vo.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/as")
public class AsController {

    @Autowired
    private AnswerApi answerApi;

    //分页查询所有
    @RequiresPermissions("qa:list:*")
    @GetMapping("/pageAsList")
    public Map<String,Object> pageAsList(Integer page,Integer limit){
        QueryAnswerVO myPage = new QueryAnswerVO();
        myPage.setCurrentPage(page);
        myPage.setPageSize(limit);

        Result<List<Answer>> listResult = answerApi.selectPage(myPage);
        Map<String,Object> map = new HashMap<>();
        map.put("data",listResult.getData());
        map.put("count",answerApi.queryCount(myPage).getData());
        map.put("code",0);
        return map;
    }

    //上下架
    @RequiresPermissions("qa:list:*")
    @PutMapping
    public Result editState(@RequestBody UpdAnswerChooseVO qaAnswerVO){
        return answerApi.updChoose(qaAnswerVO);
    }


    @GetMapping("/queryList")
    public String queryAnswerListByQid(@PathVariable("id")Long id, Model model){
        QueryAnswerVO myPage = new QueryAnswerVO();
        myPage.setQuestionId(id);

        model.addAttribute("data",new ArrayList<>());
        return "page/qs/qs-look";
    }


    //=================uncheck==========================

    //分页查询未审核回答
    @RequiresPermissions("qa:list:*")
    @GetMapping("/un/pageAsUncheckList")
    public Map<String,Object> pageAsUncheckList(Integer page,Integer limit){
        QueryAnswerAuditVO myPage = new QueryAnswerAuditVO();
        myPage.setCurrentPage(page);
        myPage.setPageSize(limit);
        myPage.setStatus(0);
        Result<List<AnswerAudit>> listResult = answerApi.queryAnswer(myPage);
        Map<String,Object> map = new HashMap<>();
        map.put("data",listResult.getData());
        map.put("count",answerApi.queryAuditCount(myPage).getData());
        map.put("code",0);
        return map;
    }

    //审核
    @RequiresPermissions("qa:edit:*")
    @PutMapping("/un")
    public Result editCheck(@RequestBody UpdAnswerUncheckedStatusVO updAnswerUncheckedStatusVO){
        return answerApi.updStatus(updAnswerUncheckedStatusVO);
    }

}

